// JavaScript Document
function gg_init()
		    {
		  		if (!window.google || !google.gears) {
		    		return;
		  		}
		  		googleGearInstalled = true;

		        try {
		            db = google.gears.factory.create('beta.database', '1.0');
		        	googleGearGivenPermission = true;
		        } catch (ex) {
		        	googleGearGivenPermission = false;
		            //setError('Could not create database: ' + ex.message);
		        }

		        if (db) {
					console.log("here");
		            db.open('gantt-db');
					var sqlArr=new Array()
		        }
}

function gg_db_delrow(rid,uid){
	db.execute("DELETE from eddy_gantt where id="+rid);
}
function gg_db_addrow(pid){
	var rs=db.execute("SELECT MAX(id) From eddy_gantt");
	mid=rs.field(0);
	mid=mid+1;
	db.execute("INSERT INTO eddy_gantt (id, wbs_name, wbs_days, wbs_position, wbs_progress, wbs_order, project_id) VALUES("+mid+", '', 0, 0, 0, 0, "+pid+")");
	var rs=db.execute("SELECT last_insert_rowid() AS lir");
	lid=rs.field(0);
	rec=lid+"##0#0#0#0#0";
	return rec;
}
function gg_db_updaterow(id,name,days,pos,prg,pid){
	db.execute("UPDATE eddy_gantt set wbs_name='"+name+"',wbs_days="+days+",wbs_position="+pos+",wbs_progress="+prg+",wbs_order=1,project_id="+pid+" where id="+id);
}

function gg_db_project(uid){
	GPRows = new Array(); 
	var rs=db.execute("select * from project where user_id="+uid);
	i=0;
	while (rs.isValidRow()) {
		console.log("ROW"+i);
		GPRows[i]=rs.field(0)+"#"+rs.field(1);
		i++;
		rs.next();
    }
	return GPRows;

}
function gg_db_rows(project_id){
	GRows = new Array(); 
	var rs=db.execute("select * from eddy_gantt where project_id="+project_id);
	i=0;
	while (rs.isValidRow()) {
		console.log("ROW"+i);
		GRows[i]=rs.field(0)+"#"+rs.field(1)+"#"+rs.field(2)+"#"+rs.field(3)+"#"+rs.field(4)+"#"+rs.field(5)+"#"+rs.field(6);
		i++;
		rs.next();
    }
	return GRows;
}